package main.java.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class RegTest {
    public static void main(String[] args){
        try(Connection connection = DBUtil.getConnection()) {
            System.out.println("成功连接数据库");
            Scanner scanner = new Scanner(System.in);
            Statement statement = connection.createStatement();
            System.out.println("请输入用户名");
            String userName = scanner.nextLine();
            System.out.println("请输入密码");
            String password = scanner.nextLine();
            System.out.println("请输入昵称");
            String nickName = scanner.nextLine();
            System.out.println("请输入年龄");
            int age = scanner.nextInt();
            String sql = "INSERT INTO userinfo(username,password,nickname,age)\n" +
                    "VALUES ('"+userName+"','"+password+"','"+nickName+"',"+age+")";
            int count = statement.executeUpdate(sql);
            System.out.println(count>0?"注册成功":"注册失败");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
